package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.entity.ResponseResult;
import com.web.entity.User;
import com.web.service.StudentService;
import com.web.service.UserService;
import com.web.service.impl.UserServiceImpl;

import jakarta.annotation.Resource;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 更新用户数据接口
 */
@WebServlet("/updateUser")
public class UpdateUserServlet extends HttpServlet {

    @Resource
    UserService userService ;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得参数
        String sid = req.getParameter("id");
        String nickname = req.getParameter("nickname");
        String icon = req.getParameter("icon");
        String email = req.getParameter("email");
        int id = 0;
        if(sid != null){
            id = Integer.parseInt(sid);
        }
        //更新用户信息
        User user = new User();
        user.setId(id);
        user.setEmail(email);
        user.setNickname(nickname);
        user.setIcon(icon);
        userService.updateUser(user);
        //返回信息给前端
        resp.getWriter().write(JSON.toJSONString(new ResponseResult(200,"OK",null)));
    }
}
